//
//  WSDLNetWork.m
//  HTP
//
//  Created by admin on 15/10/25.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "WSDLNetWork.h"

@implementation WSDLNetWork
+(void)shareInstance:(RequestBlock)doBlock withResult:(ResultBlock)result throwError:(ErrorBlock)error{
    __block interfaceSoapBindingResponse *response;
    interfaceSoapBinding *bind = [interface interfaceSoapBinding];
    bind.logXMLInOut = NO;
    dispatch_queue_t queue = dispatch_get_global_queue(2, 0);
    dispatch_async(queue, ^{
        response =  doBlock(bind);
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (response.error) {
                error(response.error);
            }else{
                for (id body in response.bodyParts) {
                    if ([body isKindOfClass:[SOAPFault class]]) {
                        error(nil);
                        return ;
                    }
                    NSData *jsonData = [[body return_ ] dataUsingEncoding:NSUTF8StringEncoding];
                    result([jsonData objectFromJSONData]);
                }
                
            }
        });
    });
}
@end
